<?php

!defined('IN_FENGTOP') && exit('Access Denied');
 
class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('category');
		$this->load('list');
	}

	function dogroup(){
		$sqlGroup = "SELECT * 
		               FROM  `".DB_TABLEPRE."category` 
		              WHERE  `plate` = '{$this->get[2]}'
		           ORDER BY `displayorder` ASC, `fid` ASC";
		$group      = $this->db->get_array($sqlGroup);
		//$totalGroup = $this->db->num_rows($sqlGroup);

		$sqlForum = "SELECT * 
		               FROM  `".DB_TABLEPRE."category` 
		              where `fup` = '{$group[0]['fid']}'
		         ORDER BY `displayorder` ASC, `fid` ASC";
		$forum      = $this->db->get_array($sqlForum);
		//$totalForum = $this->db->num_rows($sqlForum);
//print_r($group);
//var_dump($group[0]['navigation']);
		if($group[0]['navigation']){
			$category = $_ENV['category']->get_categrory_tree($group[0]['navigation']);
			$this->view->assign('category',$category);
//print_r($category);
		}else{
			$categoryJson = $_ENV['category']->add_category($group[0]['fid']);
			$category     = $_ENV['category']->get_categrory_tree($categoryJson);
			$this->view->assign('category',$category);
		}
		$this->view->assign('group',$group);
		//$this->view->assign('totalGroup',$totalGroup);
		$this->view->assign('forum',$forum);
		//$this->view->assign('totalForum',$totalForum);
		
		$this->view->display('group.tpl');
	}
	
	function doforum(){
		
		$sqlForum = "SELECT * from `".DB_TABLEPRE."category` 
						  where `plate` = '{$this->get[2]}'
					   ORDER BY `displayorder` ASC, `fid` ASC";
		$forum      = $this->db->get_array($sqlForum);
		$forumCount = count($forum);
//print_r($forum);
		
		$sqlSub = "SELECT * from `".DB_TABLEPRE."category` 
						where `fup` = '{$forum[0]['fid']}'
					ORDER BY `displayorder` ASC, `fid` ASC";
		$sub      = $this->db->get_array($sqlSub);
//print_r($sub);
		for($i = 1; $i < $forumCount; $i++){
			$sqlSub = "SELECT * from `".DB_TABLEPRE."category` 
							where `fup` = '{$forum[$i]['fid']}'
						ORDER BY `displayorder` ASC, `fid` ASC";
			$sub      = $this->db->get_array($sqlSub);
		}
		
		if($forum[0]['navigation']){
			$category = $_ENV['category']->get_categrory_tree($forum[0]['navigation']);
			$this->view->assign('category',$category);
		}else{
			$categoryJson = $_ENV['category']->add_category($forum[0]['fid']);
			$category     = $_ENV['category']->get_categrory_tree($categoryJson);
			$this->view->assign('category',$category);
		}
		
		//$uid = $_COOKIE['uid'];

//print_r($forum);
		$getList = "select `pid`, `subject` ,`dateline` , `origin` 
		              from `".DB_TABLEPRE."post` 
		             where `fid` = {$forum[0]['fid']} 
		               and status   = '0'
						and first = 1
		          ORDER BY `dateline` DESC 
		             LIMIT 0 , 30";
//echo $getList;
		$result = $this->db->get_array($getList);
//print_r($result);
		if(is_array($result))
		{
			$forumList[]    = $result;
			$forumListCount = $this->db->num_rows($getList);
		}
//print_r($forumList);
//echo $forumCount;
		for($i = 1; $i < $forumCount; $i++){
			$getList = "select `pid`, `subject` ,`dateline`, `origin` 
						from `".DB_TABLEPRE."post` 
						where `fid` = {$forum[$i]['fid']} 
						and status   = '0'
						and first = 1
					ORDER BY `dateline` DESC 
						LIMIT 0 , 30";
//echo $getList;
			$result      = $this->db->get_array($getList);
//print_r($result);
			$forumListCount += $this->db->num_rows($getList);
			if(is_array ( $result )){
				$forumList[] = $result;
			}else {
				;//$GLOBALS['_Page']['Forums']['list'][] = $result;
			}
		}
		
//print_r($forumList);
//echo $forumListCount;
		$this->view->assign('forumList',$forumList);
		$this->view->assign('forumListCount',$forumListCount);
		$this->view->assign('forum',$forum);
		$this->view->assign('sub',$sub);
		
		$this->view->display('forum.tpl');
	}
	
	function dosub(){
		
		$sqlSub = "SELECT * from `".DB_TABLEPRE."category` 
                          where `plate` = '{$this->get[2]}'
                       ORDER BY `displayorder` ASC, `fid` ASC";
		$sub      = $this->db->get_array($sqlSub);
		$totalSub = $this->db->num_rows($sqlSub);
		
		if(empty($this->get[3])){
			$page = 1;
		}else{
			$page = max(1, intval($this->get[3]));
		}
		$num = isset($this->setting['list_prepage'])?$this->setting['list_prepage']:20;
		$start_limit = ($page - 1) * $num;
		$allnum = $_ENV['list']->get_list_num($totalSub, $sub);
		
		for($j = 0; $j < $totalSub; $j++){
			$getList = "select `pid`, `subject` ,`dateline` , `origin` 
			              from `".DB_TABLEPRE."post` 
			             where `fid`   = {$sub[$j]['fid']} 
			               and status  = '0'
			               and first   = '1'
			          ORDER BY `dateline` DESC 
			             LIMIT {$start_limit} , {$num}";
			$subPost[] = $this->db->get_array($getList);
		}
		
		if($sub[0]['navigation']){
			$category = $_ENV['category']->get_categrory_tree($sub[0]['navigation']);
			$this->view->assign('category',$category);
//print_r($category);
		}else{
			$categoryJson = $_ENV['category']->add_category($sub[0]['fid']);
			$category     = $_ENV['category']->get_categrory_tree($categoryJson);
			$this->view->assign('category',$category);
		}
		$departstr=$this->multi($allnum, $num, $page,'list-sub-'.$this->get[2]);
		$this->view->assign('departstr',$departstr);
		$this->view->assign("docsum",$allnum);
		$this->view->assign('sub',$sub);
		$this->view->assign('subPost',$subPost);
		
		$this->view->display('sub.tpl');
	}
	
}
?>
